package actions;

import java.util.*;
import java.sql.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.StudentModel;

import org.apache.struts.action.*;

public class StartReviewAction extends Action
{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		
		// Starts the review process
		// get vector of apps
		// get vector of reviewers
		// create a hashmap that maps reviewer names with app ids
		
		Vector applicants = StudentModel.getAllApplicantIds();
		Vector reviewers = StudentModel.getAllReviewers();
		
		HashMap assignments = new HashMap();
		
		for (int i = 0; i < applicants.size(); i++) {
			int rev = i % reviewers.size();
			// maps the username of a reviwer to an application id
			assignments.put( ((HashMap)reviewers.get(rev)).get("userName"), applicants.get(i));
		}

		StudentModel.writeReviewerAssignments(assignments);
	
		return mapping.findForward("success");
	}
}
